def encrypt(plaintext, key):
    lenOfText = len(plaintext)
    result = ""
    for i in range(lenOfText):
        if plaintext[i].isalpha():
            a = "A" if plaintext[i].isupper() else "a"
            result += chr((ord(plaintext[i]) - ord(a) + key) % 26 + ord(a))
        else:
            result += plaintext[i]
    return result

def vigenere(plaintext:str, key:str):
    lenOfText = len(plaintext)
    lenOfKey = len(key)
    result = ""
    for i in range(lenOfText):
        a = "A" if plaintext[i].isupper() else "a"
        j = i if i < lenOfKey else i % lenOfKey
        int_key = (ord(key[j]) - ord(a))
        result += encrypt(plaintext[i], int_key)
    return result



def changePosition(plaintext:str, t):
    result =[]
    length = len(t)
    temp =[plaintext[i:i+length]for i in range(0,len(plaintext),length)]
    for item in temp[:-1]:
        newItem=''
        for i in t:
            newItem = newItem + item[i-1]
            result.append(newItem)
    return''.join(result)+ temp[-1]


if __name__ == '__main__':
    plaintext = "zgxw is a pig"
    print(vigenere(plaintext,"b"))